<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="css/bootstrap.min.css?v=3.3.7" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/plugins/morris/morris-0.4.3.min.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
    <style>
        .el-table .warning-row {
            background: oldlace;
        }

        .el-table .success-row {
            background: #f0f9eb;
        }

        .b1 {
            width: 200px;
            overflow: hidden; /*内容会被修剪，并且其余内容是不可见的。*/
            text-overflow: ellipsis; /*显示省略符号来代表被修剪的文本*/
            white-space: nowrap; /*文本不会换行，文本会在在同一行上继续，直到遇到 <br> 标签为止。*/
        }
    </style>
</head>
<body class="gray-bg">
<div id="app">

    <el-form :inline="true" :model="wen" class="demo-form-inline">
        <el-form-item label="作者">
            <el-input v-model="wen.zuo" placeholder="作者"></el-input>
        </el-form-item>
        <el-form-item label="关键字">
            <el-input v-model="wen.guan" placeholder="关键字"></el-input>
        </el-form-item>
        <el-form-item label="文献类型">
            <el-input v-model="wen.lei" placeholder="文献类型"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="success" @click="centerVisible1= true">日期筛选</el-button>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>

    </el-form>
    <el-dialog
            title="修改"
            :visible.sync="centerVisible1"
            width="80%"
    >
        <el-date-picker
                v-model="kai"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="开始日期">
        </el-date-picker>
        至
        <el-date-picker
                v-model="jie"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="结束日期">
        </el-date-picker>
        <el-button type="primary" @click="centerVisible1 = false">确定</el-button>
        <el-button @click="centerVisible1 = false">取消</el-button>
    </el-dialog>
    <template>
        <el-table
                :data="tableData"
                style="width: 100%"
                :row-class-name="tableRowClassName"
                @selection-change="handleSelectionChange">
            </el-table-column>
            <el-table-column
                    prop="di"
                    label="文件地址名"
                    align="center"
                    width="300"
            >
            </el-table-column>
            <el-table-column
                    prop="zuo"
                    label="作者"
                    align="center"
                    width="180"
            >
            </el-table-column>
            <el-table-column
                    prop="guan"
                    label="关键字"
                    align="center"
                    width="180"
            >
            </el-table-column>
            <el-table-column
                    prop="rq"
                    label="日期"
                    sortable
                    align="center"
                    width="120"
                    column-key="date"

            >
            </el-table-column>
            <el-table-column
                    prop="lei"
                    label="文献类型"
                    align="center"
                    width="180"
                    :filters="[{ text: '期刊文章', value: '期刊文章' }, { text: '论文', value: '论文' }]"
                    :filter-method="filterTag"
                    filter-placement="bottom-end"
            >
                <template slot-scope="scope">
                    <el-tag
                            :type="scope.row.tag === '期刊文章' ? 'primary' : 'success'"
                            disable-transitions>{{scope.row.lei}}
                    </el-tag>
                </template>
            </el-table-column>
            <el-table-column
                    align="center"
                    label="操作"
                    width="350">
                <template slot-scope="scope">
                    <el-button type="danger" plain @click="kan(scope.$index, scope.row)">查看</el-button>
                    <el-button type="primary" plain @click="xiu(scope.$index, scope.row)">修改</el-button>
                    <el-button type="warning" plain @click="shan1(scope.$index, scope.row)">删除</el-button>
                    <!--修改数据的对话框表单-->
                    <el-dialog
                            title="修改"
                            :visible.sync="centerVisible"
                            width="80%"
                    >
                        <el-form ref="form" :model=" wen" label-width="80px">
                            <el-form-item label="作者">
                                <el-input v-model=" wen.zuo"></el-input>
                            </el-form-item>
                            <el-form-item label="关键字">
                                <el-input v-model=" wen.guan"></el-input>
                            </el-form-item>
                            <el-form-item label="文献类型">
                                <el-input v-model=" wen.lei"></el-input>
                            </el-form-item>
                            日期：
                            <el-date-picker
                                    v-model="wen.rq"
                                    type="date"
                                    align="right"
                                    placeholder="选择日期">
                            </el-date-picker>
                            </br> </br>
                            <el-form-item>
                                <el-button type="primary" @click="edit">提交</el-button>
                                <el-button @click="centerVisible =false">取消</el-button>
                            </el-form-item>
                        </el-form>
                    </el-dialog>
                </template>
            </el-table-column>
        </el-table>
    </template>
    <!--分页工具条-->
    <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[3, 6, 9]"
            :page-size="3"
            layout="total, sizes, prev, pager, next, jumper"
            :total="totalCount">
    </el-pagination>
</div>
<script src="js/vue.js"></script>
<script src="element-ui/lib/index.js"></script>
<link rel="stylesheet" href="element-ui/lib/theme-chalk/index.css">
<script src="js/axios-0.18.0.js"></script>

<!--统计代码，可删除-->
<script>
    new Vue({
        el: "#app",
        data() {
            return {
                pageSize: 3,
                // 总记录数
                totalCount: 100,
                // 当前页码
                currentPage: 1, selectedIds: [],
                dialogVisible: false, centerVisible: false,
                centerVisible1: false,
                dialogVisible1: false,
                activeIndex: '1',
                activeIndex2: '1', kai: '', jie: ''
                , wen: {
                    wen: '', di: '', zuo: '', guan: '', rq: '', lei: ''
                },
                tableData: [{
                    wen: '', di: '', zuo: '', guan: '', rq: '', lei: ''
                },]
            }
        },
        mounted() {
            //当页面加载完成后，发送异步请求，获取数据

            this.selectAll();

        },
        methods: {
            handleSelectionChange(val) {
                this.multipleSelection = val;

            },
            tableRowClassName({row, rowIndex}) {
                if (rowIndex === 1) {
                    return 'warning-row';
                } else if (rowIndex === 3) {
                    return 'success-row';
                }
                return '';
            },
            handleSizeChange(val) {
                this.pageSize = val;
                this.selectAll();

            },
            handleCurrentChange(val) {
                this.currentPage = val;
                this.selectAll();
            },
            onSubmit() {
                this.selectAll();
            },
            selectAll() {
                var _this = this;
                axios({
                    method: "post",
                    url: "http://localhost:8080/wenxian-master/wj/selectByPageAndCondition?currentPage=" + this.currentPage + "&pageSize=" + this.pageSize + "&kai=" + this.kai + "&jie=" + this.jie,
                    data: this.wen

                }).then(resp => {
                    this.tableData = resp.data.rows;
                    this.totalCount = resp.data.totalCount;
                })


            },
            kan(index, row) {
                window.open("http://localhost:8080/wenxian-master/upload/" + row.di);
            },
            shan1(index, row) {
                this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //用户点击确认按钮

                    //2. 发送AJAX请求
                    var _this = this;

                    // 发送ajax请求，添加数据
                    axios({
                        method: "post",
                        url: "http://localhost:8080/wenxian-master/wj/shan",
                        data: row.di
                    }).then(function (resp) {
                        if (resp.data == "success") {
                            //删除成功

                            // 重新查询数据
                            _this.selectAll();
                            // 弹出消息提示
                            _this.$message({
                                message: '恭喜你，删除成功',
                                type: 'success'
                            });

                        }
                    })
                }).catch(() => {
                    //用户点击取消按钮

                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });


            }, xiu(index, row) {
                this.wen.wen = row.wen;
                this.wen.di = row.di;
                this.wen.zuo = row.zuo;
                this.wen.guan = row.guan;
                this.wen.rq = row.rq;
                this.wen.lei = row.lei;
                //this.brand=row.brand;
                this.centerVisible = true;
            },
            //修改数据的部分内容
            edit() {
                var _this = this;
                //发送ajax异步请求，添加数据
                axios({
                    method: "post",
                    url: "http://localhost:8080//wenxian-master/wj/xiu",
                    data: _this.wen
                }).then(function (resp) {
                    if (resp.data == "success") {
                        //关闭窗口
                        _this.centerVisible = false;
                        //查询一次
                        _this.selectAll();
                        _this.$message({
                            message: '恭喜你，修改数据成功',
                            type: 'success'
                        });
                    } else {
                        _this.$message.error('修改数据失败');
                    }
                })
            },
            resetDateFilter() {
                this.$refs.filterTable.clearFilter('date');
            },
            clearFilter() {
                this.$refs.filterTable.clearFilter();
            },
            filterTag(value, row) {
                return row.lei === value;
            }
        }
    })
</script>
</body>

</html>
